package com.bridgeintelligent.tag.webserver.dim.mgmt.service.scheduled;

import com.bridgeintelligent.tag.webserver.dim.mgmt.api.BaseCode;
import com.bridgeintelligent.tag.webserver.dim.mgmt.api.DepartmentRep;
import com.bridgeintelligent.tag.webserver.dim.mgmt.api.DimRep;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * Created by JackCheung on 2019/9/8 10:27 PM.
 */
@AllArgsConstructor
@RestController
@RequestMapping(value = "/api/refreshDepartment")
public class RefreshDepartmentController {

    private DepartmentScheduledService departmentScheduledService;
    private DepartmentApiUtils departmentApiUtils;


    @GetMapping("/refreshCache")
    public DimRep refreshCache() {
        DepartmentApi departmentApi = departmentApiUtils.build(DepartmentApi.class);
        DepartmentRep departmentRep = departmentApi.queryDepatment();
        departmentScheduledService.updateDepartment(departmentRep);
        return new DimRep(BaseCode.SUCCESS);
    }
}
